package org.springblade.modules.admin.vo.parts;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.enums.EmerProcTypeEnum;
import org.springblade.modules.admin.enums.WorkOrderTypeEnum;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author zcc
 * @version 1.0
 * @date 2022/6/30 8:43
 */
@Data
@ApiModel("报价记录model")
public class SparepartPricesListVo {

	@ApiModelProperty("当前记录id")
	private Long id;

	@ApiModelProperty("项目名称")
	private String buildingName;

	@ApiModelProperty("电梯地址")
	private String elevatorAddress;

	@ApiModelProperty("工单id")
	private Long parentPlanId;

	@ApiModelProperty("申请人")
	private String createUserName;

	@ApiModelProperty("报价员名称")
	private String priceUserName;

	@ApiModelProperty("报价员审批时间")
	private String priceCheckTime;



	@ApiModelProperty("配件数量")
	private String partNum;

	@ApiModelProperty("记录id")
	private Long groupId;

	@ApiModelProperty("总价")
	private String allPrice;

	@ApiModelProperty("附件")
	private List<AttachedFileVo> attachedFile;

	/**
	 * 紧急程度
	 */
	private Integer emerProcType;

	/**
	 * 工单类型
	 */
	private Integer workOrderType;

	/**
	 * 紧急程度描述
	 */
	private String emerProcTypeName;

	/**
	 * 工单类型描述
	 */
	private String workOrderTypeName;

	public void setEmerProcType(Integer emerProcType) {
		if(Func.isNotEmpty(emerProcType)){
			this.emerProcTypeName = EmerProcTypeEnum.getName(emerProcType);
		}
		this.emerProcType = emerProcType;
	}

	public void setWorkOrderType(Integer workOrderType) {
		if(Func.isNotEmpty(workOrderType)){
			this.workOrderTypeName = WorkOrderTypeEnum.getName(workOrderType);
		}
		this.workOrderType = workOrderType;
	}

	public void setPartNum(String partNum) {
		this.partNum = partNum;
		if(StrUtil.isNotEmpty(partNum)){
			final String[] split = partNum.split(",");
			if(split.length==1){
				this.partNum = split[0];
			}else{
				int counts = 0;
				for(String count:split){
					counts=counts+Convert.toInt(count,0);
				}
				this.partNum = Convert.toStr(counts);
			}
		}
	}

	public void setAllPrice(String allPrice) {
		this.allPrice = allPrice;
		if(StrUtil.isNotEmpty(allPrice)){
			final String[] split = allPrice.split(",");
			if(split.length==1){
				this.allPrice = split[0];
			}else{
				BigDecimal bigDecimal1 = new BigDecimal(0.00);
				for(String prices:split){
					final BigDecimal bigDecimal = Convert.toBigDecimal(prices);
					bigDecimal1 = bigDecimal1.add(bigDecimal);
				}
				this.allPrice=bigDecimal1.toString();
			}
		}
	}
}


